/*
 * $Id: l2.h,v 1.25.6.2 Broadcom SDK $
 * 
 * $Copyright: Copyright 2011 Broadcom Corporation.
 * This program is the proprietary software of Broadcom Corporation
 * and/or its licensors, and may only be used, duplicated, modified
 * or distributed pursuant to the terms and conditions of a separate,
 * written license agreement executed between you and Broadcom
 * (an "Authorized License").  Except as set forth in an Authorized
 * License, Broadcom grants no license (express or implied), right
 * to use, or waiver of any kind with respect to the Software, and
 * Broadcom expressly reserves all rights in and to the Software
 * and all intellectual property rights therein.  IF YOU HAVE
 * NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE
 * IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
 * ALL USE OF THE SOFTWARE.  
 *  
 * Except as expressly set forth in the Authorized License,
 *  
 * 1.     This program, including its structure, sequence and organization,
 * constitutes the valuable trade secrets of Broadcom, and you shall use
 * all reasonable efforts to protect the confidentiality thereof,
 * and to use this information only in connection with your use of
 * Broadcom integrated circuit products.
 *  
 * 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS
 * PROVIDED "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
 * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
 * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY
 * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
 * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
 * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
 * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING
 * OUT OF USE OR PERFORMANCE OF THE SOFTWARE.
 * 
 * 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
 * BROADCOM OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL,
 * INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER
 * ARISING OUT OF OR IN ANY WAY RELATING TO YOUR USE OF OR INABILITY
 * TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF
 * THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR USD 1.00,
 * WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING
 * ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.$
 * 
 * DO NOT EDIT THIS FILE!
 * This file is auto-generated.
 * Edits to this file will be lost when it is regenerated.
 */

#ifndef __BCMX_L2_H__
#define __BCMX_L2_H__

#include <bcm/types.h>
#include <bcmx/bcmx.h>
#include <bcmx/lport.h>
#include <bcmx/lplist.h>
#include <bcm/l2.h>

/* Device-independent L2 address structure. */
typedef struct bcmx_l2_addr_s {
    uint32 flags;       /* BCM_L2_xxx flags. */
    bcm_mac_t mac;      /* 802.3 MAC address. */
    bcm_vlan_t vid;     /* VLAN identifier. */
    bcmx_lport_t lport; /* Logical port number. */
    bcm_trunk_t tgid;   /* Trunk group ID. */
    int trunk_sel;      /* Trunk port select formula. */
    bcm_cos_t cos_dst;  /* COS based on dst addr. */
    bcm_cos_t cos_src;  /* COS based on src addr. */
    int l2mc_index;     /* XGS: index in L2MC table. For SBX chips it is the
                           Multicast Group index */
    int auth;           /* Used if auth enabled on port. */
    int bcm_unit;       /* The bcm_unit number can be used to record the
                           reporting unit for adds and deletes.  This may differ
                           from the unit associated with the lport. */
    int group;          /* Group number for FP. */
} bcmx_l2_addr_t;

/* Device-independent L2 cache address structure. */
typedef struct bcmx_l2_cache_addr_s {
    uint32 flags;               /* BCM_L2_CACHE_xxx flags. */
    bcm_mac_t mac;              /* Destination MAC address to match. */
    bcm_mac_t mac_mask;         /* MAC address mask. */
    bcm_vlan_t vlan;            /* VLAN to match. */
    bcm_vlan_t vlan_mask;       /* VLAN mask. */
    bcmx_lport_t src_port;      /* Ingress port to match (BCM5660x). */
    bcmx_lport_t src_port_mask; /* Ingress port mask (must be 0 if not
                                   BCM5660x). */
    bcmx_lport_t dest_lport;    /* Switch destination port. */
    bcm_trunk_t dest_trunk;     /* Switch destination trunk ID. */
    int prio;                   /* Internal priority, use -1 to not set. */
    bcmx_lplist_t dest_ports;   /* Destination ports for Multiport L2 address
                                   forwarding. */
    int lookup_class;           /* Classification class ID. */
} bcmx_l2_cache_addr_t;

/* L2 learn limit structure. */
typedef struct bcmx_l2_learn_limit_s {
    uint32 flags;       /* BCM_L2_LEARN_LIMIT_xxx actions and qualifiers. */
    bcm_vlan_t vlan;    /* VLAN identifier. */
    bcm_vpn_t vpn;      /* VPN identifier. */
    bcmx_lport_t lport; /* Port number. */
    bcm_trunk_t trunk;  /* Trunk identifier. */
    int limit;          /* Maximum number of learned entries, -1 for unlimited. */
} bcmx_l2_learn_limit_t;

/* 
 * Initialize an L2 address structure to a specified MAC address and VLAN
 * ID.
 */
extern void bcmx_l2_addr_t_init(
    bcmx_l2_addr_t *l2addr, 
    bcm_mac_t mac_addr, 
    bcm_vlan_t vid);

/* Backward compatibility. */
#define bcmx_l2_addr_init       bcmx_l2_addr_t_init 

/* Initialize an L2 learn limit structure. */
extern void bcmx_l2_learn_limit_t_init(
    bcmx_l2_learn_limit_t *limit);

/* Add an L2 address entry to the specified device. */
extern int bcmx_l2_addr_add(
    bcmx_l2_addr_t *l2addr, 
    bcmx_lplist_t *port_block);

/* Delete an L2 address entry from the specified device. */
extern int bcmx_l2_addr_delete(
    bcm_mac_t mac, 
    bcm_vlan_t vid);

/* Delete L2 entries associated with a destination port. */
extern int bcmx_l2_addr_delete_by_port(
    bcmx_lport_t port, 
    uint32 flags);

/* Delete L2 entries associated with a MAC address. */
extern int bcmx_l2_addr_delete_by_mac(
    bcm_mac_t mac, 
    uint32 flags);

/* Delete L2 entries associated with a VLAN. */
extern int bcmx_l2_addr_delete_by_vlan(
    bcm_vlan_t vid, 
    uint32 flags);

/* Delete L2 entries associated with a trunk. */
extern int bcmx_l2_addr_delete_by_trunk(
    bcm_trunk_t tid, 
    uint32 flags);

/* 
 * Delete L2 entries associated with a MAC address and a destination
 * port.
 */
extern int bcmx_l2_addr_delete_by_mac_port(
    bcm_mac_t mac, 
    bcmx_lport_t port, 
    uint32 flags);

/* Delete L2 entries associated with a VLAN and a destination port. */
extern int bcmx_l2_addr_delete_by_vlan_port(
    bcm_vlan_t vid, 
    bcmx_lport_t port, 
    uint32 flags);

/* Delete L2 entries associated with a VLAN and a trunk. */
extern int bcmx_l2_addr_delete_by_vlan_trunk(
    bcm_vlan_t vid, 
    bcm_trunk_t tid, 
    uint32 flags);

/* Check if an L2 entry is present in the L2 table. */
extern int bcmx_l2_addr_get(
    bcm_mac_t mac_addr, 
    bcm_vlan_t vid, 
    bcmx_l2_addr_t *l2addr, 
    bcmx_lplist_t *port_block);

/* 
 * Callback function used for receiving notification about insertions
 * into and deletions from the L2 table dynamically as they occur. Valid
 * operations are: delete, add, and report. A report with l2addr=NULL
 * indicates a scan completion of the L2 table.
 */
typedef void (*bcmx_l2_notify_f)(
    bcmx_l2_addr_t *l2addr, 
    int insert, 
    void *cookie);

/* Register/Unregister a callback routine for L2 subsystem. */
extern int bcmx_l2_notify_register(
    bcmx_l2_notify_f callback, 
    void *userdata);

/* Register/Unregister a callback routine for L2 subsystem. */
extern int bcmx_l2_notify_unregister(
    bcmx_l2_notify_f callback, 
    void *userdata);

/* Start/stop notifications to L2 table. */
extern int bcmx_l2_notify_start(void);

/* Start/stop notifications to L2 table. */
extern int bcmx_l2_notify_stop(void);

/* Add a device to the L2 notification list. */
extern int bcmx_l2_device_add(
    int bcm_unit);

/* Remove device from the L2 notification list. */
extern int bcmx_l2_device_remove(
    int bcm_unit);

/* Set the age timer. */
extern int bcmx_l2_age_timer_set(
    int age_seconds);

/* Get the age timer. */
extern int bcmx_l2_age_timer_get(
    int *age_seconds);

/* Get the number of BPDU addresses available. */
extern int bcmx_l2_bpdu_count(void);

/* Set the BPDU address. */
extern int bcmx_l2_bpdu_set(
    int index, 
    bcm_mac_t addr);

/* Get the BPDU address. */
extern int bcmx_l2_bpdu_get(
    int index, 
    bcm_mac_t *addr);

/* Temporarily stop/restore L2 table from changing. */
extern int bcmx_l2_addr_freeze(void);

/* Temporarily stop/restore L2 table from changing. */
extern int bcmx_l2_addr_thaw(void);

/* 
 * Given an L2 address entry, return existing addresses which could
 * conflict.
 */
extern int bcmx_l2_conflict_get(
    bcmx_l2_addr_t *addr, 
    bcmx_l2_addr_t *cf_array, 
    int cf_max, 
    int *cf_count);

/* Convert BCMX to BCM L2 address structure. */
extern int bcmx_l2_addr_to_bcm(
    int bcm_unit, 
    bcm_l2_addr_t *dest, 
    bcmx_l2_addr_t *source, 
    bcmx_lplist_t *port_block);

/* Convert BCM to BCMX L2 address structure. */
extern int bcmx_l2_addr_from_bcm(
    bcmx_l2_addr_t *dest, 
    bcmx_lplist_t *port_block, 
    bcm_l2_addr_t *source);

/* Update an L2 address entry. */
extern int bcmx_l2_addr_refresh(
    bcmx_l2_addr_t *l2addr, 
    bcmx_lplist_t *port_block);

/* 
 * Check if an L2 entry is present in the L2 table of a device that
 * contains a native port.
 */
extern int bcmx_l2_addr_native_get(
    bcm_mac_t mac_addr, 
    bcm_vlan_t vid, 
    bcmx_l2_addr_t *l2addr);

/* Check if an L2 entry is present in the L2 table on a given device. */
extern int bcmx_l2_addr_port_get(
    bcmx_lport_t port, 
    bcm_mac_t mac_addr, 
    bcm_vlan_t vid, 
    bcmx_l2_addr_t *l2addr);

/* Initialize the L2 cache. */
extern int bcmx_l2_cache_init(void);

/* Initialize an L2 cache address structure. */
extern void bcmx_l2_cache_addr_t_init(
    bcmx_l2_cache_addr_t *addr);

/* Deallocate port list in bcmx_l2_cache_addr_t. */
extern void bcmx_l2_cache_addr_t_free(
    bcmx_l2_cache_addr_t *addr);

/* Get number of L2 cache entries. */
extern int bcmx_l2_cache_size_get(
    int *size);

/* Set an L2 cache entry. */
extern int bcmx_l2_cache_set(
    int index, 
    bcmx_l2_cache_addr_t *addr, 
    int *index_used);

/* Get an L2 cache entry. */
extern int bcmx_l2_cache_get(
    int index, 
    bcmx_l2_cache_addr_t *addr);

/* Clear an L2 cache entry. */
extern int bcmx_l2_cache_delete(
    int index);

/* Clear all L2 cache entries. */
extern int bcmx_l2_cache_delete_all(void);

/* Add a destination L2 address to trigger tunnel processing. */
extern int bcmx_l2_tunnel_add(
    bcm_mac_t mac, 
    bcm_vlan_t vlan);

/* Clear a destination L2 address used to trigger tunnel processing. */
extern int bcmx_l2_tunnel_delete(
    bcm_mac_t mac, 
    bcm_vlan_t vlan);

/* Clear all destination L2 addresses used to trigger tunnel processing. */
extern int bcmx_l2_tunnel_delete_all(void);

/* Set/Get L2 addresses learn limit. */
extern int bcmx_l2_learn_limit_set(
    bcmx_l2_learn_limit_t *limit);

/* Set/Get L2 addresses learn limit. */
extern int bcmx_l2_learn_limit_get(
    bcmx_l2_learn_limit_t *limit);

/* Set/Get attributes for the specified L2 learning class. */
extern int bcmx_l2_learn_class_set(
    int lclass, 
    int lclass_prio, 
    uint32 flags);

/* Set/Get attributes for the specified L2 learning class. */
extern int bcmx_l2_learn_class_get(
    int lclass, 
    int *lclass_prio, 
    uint32 *flags);

/* Set/Get L2 learning class for the specified port. */
extern int bcmx_l2_learn_port_class_set(
    bcmx_lport_t port, 
    int lclass);

/* Set/Get L2 learning class for the specified port. */
extern int bcmx_l2_learn_port_class_get(
    bcmx_lport_t port, 
    int *lclass);

/* Replace L2 entries matching given criterions */
extern int bcmx_l2_replace(
    uint32 flags, 
    bcmx_l2_addr_t *match_addr, 
    bcmx_lport_t new_port, 
    bcm_trunk_t new_trunk);

#endif /* __BCMX_L2_H__ */
